package com.ihr360.insurance.convertor;

import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.insurance.entity.vo.MemberPlanVo;
import com.ihr360.insurance.model.dto.ledger.DecreaseMemberPlan;
import com.ihr360.shared.basicstaffinfo.dto.SyncedBasicStaffInfo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-03-16 15:23:51.
 */
@Component
public class DecreaseMemberPlanConvertor implements IConvertor<MemberPlanVo, DecreaseMemberPlan> {

    @Override
    public DecreaseMemberPlan convertEntityToDto(MemberPlanVo vo) {
        if (vo == null) {
            return null;
        }
        DecreaseMemberPlan dto = new DecreaseMemberPlan();
        SyncedBasicStaffInfo staff = new SyncedBasicStaffInfo();
        staff.setId(vo.getStaffId());
        dto.setUserId(vo.getUserId());
        dto.setStaff(staff);

        dto.setYear(vo.getYear());
        dto.setMonth(vo.getMonth());
        dto.setInLedger(vo.getInLedger());

        dto.setSocialInsurance(dto.getSocialInsurance());
        dto.setSiCompanyBenefit(dto.getSiCompanyBenefit());
        dto.setHouseFund(vo.getHouseFund());
        dto.setHfCompanyBenefit(vo.getHfCompanyBenefit());
        return dto;
    }

    @Override
    public MemberPlanVo convertDtoToEntity(DecreaseMemberPlan dto) {
        if (dto == null) {
            return null;
        }
        MemberPlanVo vo = new MemberPlanVo();
        vo.setUserId(dto.getUserId());
        vo.setStaffId(dto.getStaff().getId());
        vo.setStaffName(dto.getStaff().getStaffName());
        vo.setDepartmentId(dto.getStaff().getDepartmentId());
        vo.setDepartmentName(dto.getStaff().getDepartmentName());
        vo.setIdCardNo(dto.getStaff().getIdCardNo());

        vo.setYear(dto.getYear());
        vo.setMonth(dto.getMonth());
        vo.setInLedger(dto.getInLedger() == null ? false : dto.getInLedger());

        vo.setSocialInsurance(dto.getSocialInsurance());
        vo.setSiCompanyBenefit(dto.getSiCompanyBenefit());
        vo.setHouseFund(dto.getHouseFund());
        vo.setHfCompanyBenefit(dto.getHfCompanyBenefit());
        return vo;
    }

    public List<MemberPlanVo> convertDtosToEntities(List<DecreaseMemberPlan> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Collections.emptyList();
        }
        List<MemberPlanVo> vos = new ArrayList<>(dtos.size());
        dtos.forEach(dto -> vos.add(convertDtoToEntity(dto)));
        return vos;
    }

    public List<DecreaseMemberPlan> convertEntitiesToDtos(List<MemberPlanVo> vos) {
        if (CollectionUtils.isEmpty(vos)) {
            return Collections.emptyList();
        }
        List<DecreaseMemberPlan> dtos = new ArrayList<>(vos.size());
        vos.forEach(vo -> dtos.add(convertEntityToDto(vo)));
        return dtos;
    }
}
